package com.tanglongan.designPattern.dp21_template.demo02;

import javax.sql.DataSource;
import java.util.List;

public class MemberDao extends JdbcTemplate {

    public MemberDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<?> selectAll() throws Exception {
        String sql = "select * from t_member";
        return super.executeQuery(sql, (RowMapper<Member>) (rs, rownum) -> {
            //字段太多，可以使用原型模式
            Member member = new Member();
            member.setUsername(rs.getString("username"));
            member.setPassword(rs.getString("password"));
            member.setNickname(rs.getString("nickname"));
            member.setAge(rs.getInt("age"));
            member.setAddr(rs.getString("addr"));
            return null;
        }, null);
    }
}
